package com.huawei.hwid.api.common;

import android.accounts.Account;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.cloudservice.CloudAccount;
import com.huawei.cloudservice.CloudAccountManager;
import com.huawei.cloudservice.CloudRequestHandler;
import com.huawei.cloudservice.IntentResultHandler;
import com.huawei.cloudservice.LoginHandler;
import com.huawei.hwid.api.common.apkimpl.DummyActivity;
import com.huawei.hwid.core.a.b;
import com.huawei.hwid.core.b.a.a.f;
import com.huawei.hwid.core.b.a.a.h;
import com.huawei.hwid.core.b.a.a.i;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.hwid.core.d.d;
import com.huawei.hwid.core.d.g;
import com.huawei.hwid.core.d.l;
import com.huawei.hwid.core.d.m;
import com.huawei.hwid.core.d.n;
import com.huawei.hwid.core.datatype.HwAccount;
import com.huawei.hwid.core.datatype.UserInfo;
import com.huawei.hwid.core.encrypt.c;
import com.huawei.hwid.core.helper.handler.ErrorStatus;
import com.huawei.hwid.usecase.ReadHwAccountUseCase;
import com.huawei.hwid.usecase.ReadHwAccountUseCase.RequestValues;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

@SuppressLint({"InlinedApi"})
public class e {
    private static Object a = new Object();
    private static Map<String, ArrayList<BroadcastReceiver>> b = new HashMap();
    private HwAccount c = new HwAccount();
    private AlertDialog d;
    private Context e;
    private CloudRequestHandler f;
    private String g;
    private CloudRequestHandler h = new CloudRequestHandler(this) {
        final /* synthetic */ e a;

        {
            this.a = r1;
        }

        public void onFinish(Bundle bundle) {
            new Thread(this) {
                final /* synthetic */ AnonymousClass1 a;

                {
                    this.a = r1;
                }

                public void run() {
                    super.setName("CloudRequestHandlerThread");
                    this.a.a.a(this.a.a.g, this.a.a.e, this.a.a.f);
                }
            }.start();
        }

        public void onError(ErrorStatus errorStatus) {
            this.a.f.onError(errorStatus);
        }
    };

    static class a extends SafeBroadcastReceiver {
        private Context a = null;
        private boolean b = false;
        private LoginHandler c = null;

        public a(Context context, LoginHandler loginHandler, b bVar) {
            this.a = context;
            this.c = loginHandler;
        }

        private void a(Context context, HwAccount hwAccount) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "handleApkLogin", true);
            String str = "";
            if (hwAccount == null) {
                this.c.onLogin(null, 0);
                return;
            }
            e.b(hwAccount, context);
            com.huawei.hwid.d.a.a(context).a(hwAccount);
            CloudAccount[] a = e.a(context);
            if (!TextUtils.isEmpty(hwAccount.b())) {
                str = hwAccount.b();
            }
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "onLogin", true);
            this.c.onLogin(a, e.a(a, str));
            com.huawei.hwid.c.a.a(context).a(context, hwAccount);
        }

        private void a(Context context, Intent intent) {
            if (this.c != null) {
                a(context, e.c(context, intent));
            } else {
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "handler is null,so cannot handler message", true);
            }
        }

        private void b(Context context, Intent intent) {
            ErrorStatus errorStatus = new ErrorStatus(3002, "use the sdk: press back key");
            boolean booleanExtra = intent.getBooleanExtra(HwAccountConstants.EXTRA_IS_USE_SDK, true);
            Bundle bundleExtra = intent.getBundleExtra(HwAccountConstants.EXTRA_BUNDLE);
            if (!(bundleExtra == null || booleanExtra)) {
                int i = bundleExtra.getInt("errorcode");
                Object string = bundleExtra.getString("errorreason");
                if (!(i == 0 || TextUtils.isEmpty(string))) {
                    errorStatus = new ErrorStatus(i, string);
                }
            }
            if (this.c != null) {
                this.c.onError(errorStatus);
            }
        }

        /* JADX WARNING: inconsistent code. */
        /* Code decompiled incorrectly, please refer to instructions dump. */
        public void onReceiveMsg(android.content.Context r6, android.content.Intent r7) {
            /*
            r5 = this;
            r4 = 1;
            r1 = com.huawei.hwid.api.common.e.a;
            monitor-enter(r1);
            r0 = r5.b;	 Catch:{ all -> 0x003e }
            if (r0 == 0) goto L_0x000c;
        L_0x000a:
            monitor-exit(r1);	 Catch:{ all -> 0x003e }
        L_0x000b:
            return;
        L_0x000c:
            r0 = new android.os.Bundle;	 Catch:{ all -> 0x003e }
            r0.<init>();	 Catch:{ all -> 0x003e }
            r2 = "LoginBroadcastReceiver";
            r3 = 1;
            r0.putBoolean(r2, r3);	 Catch:{ all -> 0x003e }
            r2 = r5.a;	 Catch:{ all -> 0x003e }
            com.huawei.hwid.api.common.e.a(r2, r0);	 Catch:{ all -> 0x003e }
            r0 = 1;
            r5.b = r0;	 Catch:{ all -> 0x003e }
            monitor-exit(r1);	 Catch:{ all -> 0x003e }
            if (r7 == 0) goto L_0x000b;
        L_0x0022:
            r0 = r7.getAction();	 Catch:{ RuntimeException -> 0x0035 }
            com.huawei.hwid.api.common.e.d(r6);	 Catch:{ RuntimeException -> 0x0035 }
            r1 = "com.huawei.cloudserive.loginSuccess";
            r1 = r1.equals(r0);	 Catch:{ RuntimeException -> 0x0035 }
            if (r1 == 0) goto L_0x0041;
        L_0x0031:
            r5.a(r6, r7);	 Catch:{ RuntimeException -> 0x0035 }
            goto L_0x000b;
        L_0x0035:
            r0 = move-exception;
            r0 = "CloudAccountImpl";
            r1 = "Unhandle exception because of Intent to prevent DDOS";
            com.huawei.hwid.core.d.b.e.d(r0, r1, r4);
            goto L_0x000b;
        L_0x003e:
            r0 = move-exception;
            monitor-exit(r1);	 Catch:{ all -> 0x003e }
            throw r0;
        L_0x0041:
            r1 = "com.huawei.cloudserive.loginFailed";
            r1 = r1.equals(r0);	 Catch:{ RuntimeException -> 0x0035 }
            if (r1 == 0) goto L_0x005b;
        L_0x0049:
            r0 = "parce";
            r0 = r7.getParcelableExtra(r0);	 Catch:{ RuntimeException -> 0x0035 }
            r0 = (com.huawei.hwid.core.helper.handler.ErrorStatus) r0;	 Catch:{ RuntimeException -> 0x0035 }
            r1 = r5.c;	 Catch:{ RuntimeException -> 0x0035 }
            if (r1 == 0) goto L_0x000b;
        L_0x0055:
            r1 = r5.c;	 Catch:{ RuntimeException -> 0x0035 }
            r1.onError(r0);	 Catch:{ RuntimeException -> 0x0035 }
            goto L_0x000b;
        L_0x005b:
            r1 = "com.huawei.cloudserive.loginCancel";
            r0 = r1.equals(r0);	 Catch:{ RuntimeException -> 0x0035 }
            if (r0 == 0) goto L_0x000b;
        L_0x0063:
            r5.b(r6, r7);	 Catch:{ RuntimeException -> 0x0035 }
            goto L_0x000b;
            */
            throw new UnsupportedOperationException("Method not decompiled: com.huawei.hwid.api.common.e.a.onReceiveMsg(android.content.Context, android.content.Intent):void");
        }
    }

    public static void a(Context context, Intent intent, int i, CloudRequestHandler cloudRequestHandler) {
        if (!o.a(context, cloudRequestHandler)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "setLogoutIntent: context or cloudRequestHandler is null", true);
        } else if (!com.huawei.hwid.core.d.b.h(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "setLogoutIntent:can not use hwid", true);
            cloudRequestHandler.onError(new ErrorStatus(33, "hwid is not exit"));
        } else if (!o.b(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "setLogoutIntent:hwid is not exit", true);
            cloudRequestHandler.onError(new ErrorStatus(34, "hwid is not exit"));
        } else if (o.a(context, 20302000)) {
            cloudRequestHandler.onError(new ErrorStatus(35, "hwid version must be higher than 2.3.2"));
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "apk version is low", true);
        } else if (i < 0 || intent == null || !o.a(context, intent)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "priority or intent is invalid!", true);
            cloudRequestHandler.onError(new ErrorStatus(12, "parameter can not be empty, priority should not be less than 0, Intent must be valid"));
        } else {
            com.huawei.hwid.api.common.apkimpl.a.a(context, intent, i, cloudRequestHandler);
        }
    }

    public static void a(Context context, Intent intent, int i, int i2, CloudRequestHandler cloudRequestHandler) {
        if (!o.a(context, cloudRequestHandler)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "setLogoutIntent: context or cloudRequestHandler is null", true);
        } else if (!com.huawei.hwid.core.d.b.h(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "setLogoutIntent:can not use hwid", true);
            cloudRequestHandler.onError(new ErrorStatus(33, "hwid is not exit"));
        } else if (!o.b(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "setLogoutIntent:hwid is not exit", true);
            cloudRequestHandler.onError(new ErrorStatus(34, "hwid is not exit"));
        } else if (o.a(context, 20604324)) {
            cloudRequestHandler.onError(new ErrorStatus(35, "hwid version must be higher than 2.6.4"));
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "apk version is low", true);
        } else if (i < 0 || intent == null || !o.a(context, intent)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "priority or intent is invalid!", true);
            cloudRequestHandler.onError(new ErrorStatus(12, "parameter can not be empty, priority should not be less than 0, Intent must be valid"));
        } else if (i2 == 0 || 1 == i2) {
            com.huawei.hwid.api.common.apkimpl.a.a(context, intent, i, i2, cloudRequestHandler);
        } else {
            com.huawei.hwid.core.d.b.e.d("CloudAccountImpl", "flag is invalid!", true);
            cloudRequestHandler.onError(new ErrorStatus(12, "parameter flag is invalid"));
        }
    }

    public static void a(Context context, String str, Bundle bundle, LoginHandler loginHandler) {
        int i = 0;
        if (!a(context, loginHandler)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "getAccountsByType: context or handler is null", true);
        } else if (!com.huawei.hwid.core.d.b.h(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "can not use huawei checkIsUseHuaweiAccount", true);
            loginHandler.onError(new ErrorStatus(33, "hwid is not exit"));
        } else if (o.b(context)) {
            o.a(loginHandler);
            d(context);
            if (bundle != null) {
                i = bundle.getInt(CloudAccountManager.KEY_LOGIN_CHANNEL, 0);
            } else {
                bundle = new Bundle();
            }
            if (i == 0) {
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "loginChannel can't be null!", true);
                loginHandler.onError(new ErrorStatus(12, "loginChannel can't be null!"));
                return;
            }
            if (TextUtils.isEmpty(str)) {
                str = com.huawei.hwid.core.d.b.c(context);
            }
            if (c(context, str, loginHandler)) {
                d.a(str);
                com.huawei.hwid.core.a.a.a(context).a(String.valueOf(i));
                com.huawei.hwid.api.common.apkimpl.a.a(context, str, "", bundle, loginHandler);
            }
        } else {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "huaweiid is not exit", true);
            loginHandler.onError(new ErrorStatus(34, "hwid is not exit"));
        }
    }

    public static void a(Activity activity, LoginHandler loginHandler, int i, String str) {
        if (o.a((Context) activity, 20504100)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "hwid apk version is low", true);
            loginHandler.onError(new ErrorStatus(35, "hwid is low version"));
        } else if (i == 0) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "loginChannel can't be null!", true);
            loginHandler.onError(new ErrorStatus(12, "loginChannel can't be null!"));
        } else {
            o.a(loginHandler);
            d.a(str);
            com.huawei.hwid.core.a.a.a((Context) activity).a(String.valueOf(i));
            Intent intent = new Intent();
            intent.setClass(activity, DummyActivity.class);
            intent.putExtra("requestTokenType", str);
            Bundle bundle = new Bundle();
            bundle.putBoolean("isFromApk", true);
            bundle.putBoolean("IS_LOGIN_BY_ACTIVITY", true);
            intent.putExtra(HwAccountConstants.EXTRA_BUNDLE, bundle);
            intent.setFlags(1048576);
            activity.startActivity(intent);
        }
    }

    private static boolean c(Context context, String str, LoginHandler loginHandler) {
        if (context.getPackageName().equals(str)) {
            return true;
        }
        loginHandler.onError(new ErrorStatus(12, "tokenType is not the same as package name"));
        return false;
    }

    public static int a(CloudAccount[] cloudAccountArr, String str) {
        if (!(TextUtils.isEmpty(str) || cloudAccountArr == null || cloudAccountArr.length <= 0)) {
            for (int i = 0; i < cloudAccountArr.length; i++) {
                if (str.equalsIgnoreCase(cloudAccountArr[i].getAccountName())) {
                    return i;
                }
            }
        }
        return -1;
    }

    public static CloudAccount[] a(Context context) {
        if (context == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "context is null", true);
            return new CloudAccount[0];
        }
        HwAccount b = com.huawei.hwid.d.a.a(context).b();
        if (b != null) {
            CloudAccount[] cloudAccountArr = new CloudAccount[1];
            e eVar = new e();
            eVar.a(b);
            cloudAccountArr[0] = new CloudAccount(eVar);
            return cloudAccountArr;
        }
        com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "hwAccount is null error", true);
        return new CloudAccount[0];
    }

    public static void b(Context context) {
        if (context == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "context is null", true);
            return;
        }
        com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "clear all accout data", true);
        String c = com.huawei.hwid.core.d.b.c(context);
        o.a(context, "");
        com.huawei.hwid.c.a.a(context).b(context, c);
    }

    public static void a(Context context, LoginHandler loginHandler, b bVar) {
        if (context == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "context is null", true);
            return;
        }
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(HwAccountConstants.ACTION_LOGIN_SUCCESS);
        intentFilter.addAction(HwAccountConstants.ACTION_LOGIN_FAILED);
        intentFilter.addAction(HwAccountConstants.ACTION_LOGIN_CANCEL);
        if (b.containsKey("LoginBroadcastReceiver")) {
            d(context, "LoginBroadcastReceiver");
        }
        BroadcastReceiver aVar = new a(context, loginHandler, bVar);
        try {
            context.registerReceiver(aVar, intentFilter);
            a(aVar, "LoginBroadcastReceiver");
        } catch (Exception e) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "BroadcastReceiver components are not allowed to register to receive intents", true);
        }
    }

    private static HwAccount c(Context context, Intent intent) {
        if (intent.hasExtra(HwAccountConstants.EXTRA_HWACCOUNT)) {
            return (HwAccount) intent.getParcelableExtra(HwAccountConstants.EXTRA_HWACCOUNT);
        }
        if (intent.hasExtra(HwAccountConstants.EXTRA_ACCOUNT_BUNDLE)) {
            return o.a(context, intent.getBundleExtra(HwAccountConstants.EXTRA_ACCOUNT_BUNDLE));
        }
        if (intent.hasExtra(HwAccountConstants.EXTRA_BUNDLE)) {
            return o.a(context, intent.getBundleExtra(HwAccountConstants.EXTRA_BUNDLE));
        }
        return null;
    }

    public static String c(Context context) {
        if (!com.huawei.hwid.core.d.b.h(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "can not use hwid", true);
            return "";
        } else if (o.b(context)) {
            String str = "";
            if (context != null) {
                return o.a(context);
            }
            return str;
        } else {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "hwid is not exit", true);
            return "";
        }
    }

    public static boolean a(Context context, String str) {
        if (context != null) {
            return com.huawei.hwid.c.a.a(context).c(context, str);
        }
        com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "context is null", true);
        return false;
    }

    public static void a(Context context, String str, LoginHandler loginHandler) {
        if (a(context, loginHandler)) {
            String c = c(context, str);
            d.a(c);
            if (!com.huawei.hwid.core.d.b.a(context)) {
                loginHandler.onError(new ErrorStatus(5, context.getString(l.a(context, "CS_no_network_content"))));
                return;
            } else if (!com.huawei.hwid.core.d.b.a(context, (int) HwAccountConstants.NO_SUBID)) {
                loginHandler.onError(new ErrorStatus(6, context.getString(l.a(context, "CS_sim_card_unavailable"))));
                return;
            } else if (!com.huawei.hwid.core.d.b.h(context)) {
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "can not use hwid", true);
                loginHandler.onError(new ErrorStatus(33, "hwid is not exit"));
                return;
            } else if (o.b(context)) {
                d(context);
                if (TextUtils.isEmpty(c)) {
                    c = com.huawei.hwid.core.d.b.c(context);
                }
                if (VERSION.SDK_INT > 22 || com.huawei.hwid.core.d.b.a(context.getPackageManager(), "android.permission.SEND_SMS", "com.huawei.hwid")) {
                    com.huawei.hwid.api.common.apkimpl.a.a(context, c, loginHandler);
                    return;
                } else {
                    loginHandler.onError(new ErrorStatus(17, "no permission to send sms"));
                    return;
                }
            } else {
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "hwid is not exit", true);
                loginHandler.onError(new ErrorStatus(34, "hwid is not exit"));
                return;
            }
        }
        com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "quickLogin: context or loginHandler is null", true);
    }

    public static CloudAccount b(Context context, String str) {
        if (context == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "context is null", true);
            return null;
        } else if (TextUtils.isEmpty(str)) {
            com.huawei.hwid.core.d.b.e.e("CloudAccountImpl", "get account by userID failed, the userID is null!", true);
            return null;
        } else if (!com.huawei.hwid.core.d.b.h(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "can not use hwid", true);
            return null;
        } else if (o.b(context)) {
            HwAccount d = com.huawei.hwid.core.d.b.d(context, str);
            if (d != null) {
                e eVar = new e();
                eVar.a(d);
                com.huawei.hwid.core.d.b.e.e("CloudAccountImpl", "get account by userID success!", true);
                return new CloudAccount(eVar);
            }
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "get account by userID failed, there is no matching account!", true);
            return null;
        } else {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "hwid is not exit", true);
            return null;
        }
    }

    public static void b(Context context, String str, LoginHandler loginHandler) {
        if (context == null || loginHandler == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "context is null", true);
        } else if (TextUtils.isEmpty(str)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "get account by userID failed, the userID is null!", true);
        } else if (!com.huawei.hwid.core.d.b.h(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "can not use hwid", true);
        } else if (o.b(context)) {
            d(context, str, loginHandler);
        } else {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "hwid is not exit", true);
            loginHandler.onError(new ErrorStatus(34, "hwid is not exit"));
        }
    }

    private static void d(Context context, String str, LoginHandler loginHandler) {
        new com.huawei.hwid.b(com.huawei.hwid.d.a()).a(new ReadHwAccountUseCase(context), new RequestValues(true), new 2(loginHandler, str));
    }

    public static synchronized void d(Context context) {
        synchronized (e.class) {
            com.huawei.hwid.core.d.b.e.a(context);
        }
    }

    public static void a(Context context, String str, String str2, String str3, String str4, CloudRequestHandler cloudRequestHandler, Bundle bundle) {
        if (!o.a(context, cloudRequestHandler)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "checkPassWord: context or cloudRequestHandler is null", true);
        } else if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2) || TextUtils.isEmpty(str4)) {
            com.huawei.hwid.core.d.b.e.e("CloudAccountImpl", "error: parameter is invalid", true);
            cloudRequestHandler.onError(new ErrorStatus(12, "parameter is invalid"));
        } else if (!com.huawei.hwid.core.d.b.a(context)) {
            com.huawei.hwid.core.d.b.e.e("CloudAccountImpl", "error: have no network", true);
            cloudRequestHandler.onError(new ErrorStatus(5, context.getString(l.a(context, "CS_no_network_content"))));
        } else if (!o.b(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "hwid is not exit", true);
            cloudRequestHandler.onError(new ErrorStatus(34, "hwid is not exit"));
        } else if (com.huawei.hwid.core.d.b.e(str3)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "this is third account", true);
            Bundle bundle2 = new Bundle();
            bundle2.putBoolean(HwAccountConstants.SERVICETOKENAUTH_IS_SECCUSS, true);
            cloudRequestHandler.onFinish(bundle2);
        } else {
            String c;
            if (str3 == null) {
                c = com.huawei.hwid.core.d.b.c(str);
            } else {
                c = str3;
            }
            com.huawei.hwid.core.b.a.a iVar = new i(context, str, c.b(str2), c, str4);
            iVar.a(context, iVar, str, cloudRequestHandler);
        }
    }

    private static String c(Context context, String str) {
        if (TextUtils.isEmpty(str)) {
            return com.huawei.hwid.core.d.b.l(context);
        }
        g.a(context, HwAccountConstants.TOKEN_TYPE, str);
        return str;
    }

    public static void a(Context context, String str, CloudRequestHandler cloudRequestHandler, Bundle bundle) {
        if (!o.a(context, cloudRequestHandler)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "logoutHwIdByUserId: context or cloudRequestHandler is null", true);
        } else if (TextUtils.isEmpty(str)) {
            if (cloudRequestHandler != null) {
                cloudRequestHandler.onError(new ErrorStatus(12, "userId is empty"));
            }
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "userId is empty", true);
        } else if (com.huawei.hwid.core.d.b.b(context, HwAccountConstants.ACTION_LOGOUT_FOR_APP)) {
            CloudAccount b = b(context, str);
            HwAccount hwAccount = null;
            if (b != null) {
                hwAccount = b.getAccountData();
            }
            if (com.huawei.hwid.core.d.b.b(context, HwAccountConstants.ACTION_LOGOUT_FOR_APP_BY_USERID)) {
                d(context, cloudRequestHandler);
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "start logout listener", true);
            } else {
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "hwid is not send broadcast", true);
            }
            if (hwAccount != null) {
                a(context, str, hwAccount.b(), cloudRequestHandler);
                return;
            }
            String str2 = "";
            if (bundle != null) {
                a(context, str, bundle.getString("accountName"), cloudRequestHandler);
            }
        } else if (cloudRequestHandler != null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "HwID is not install or version isn't support this port!", true);
            cloudRequestHandler.onError(new ErrorStatus(20, "HwID is not install or version isn't support this port!"));
        }
    }

    private static void d(Context context, CloudRequestHandler cloudRequestHandler) {
        if (context == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "context is null", true);
            return;
        }
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(HwAccountConstants.ACTION_LOGOUT_CANCEL);
        intentFilter.addAction(HwAccountConstants.ACTION_LOGOUT_FAIL);
        intentFilter.addAction("com.huawei.hwid.ACTION_REMOVE_ACCOUNT");
        if (b.containsKey("LogoutBroadcastReceiver")) {
            d(context, "LogoutBroadcastReceiver");
        }
        BroadcastReceiver bVar = new b(context, cloudRequestHandler);
        try {
            context.registerReceiver(bVar, intentFilter);
            a(bVar, "LogoutBroadcastReceiver");
        } catch (Exception e) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "BroadcastReceiver components are not allowed to register to receive intents", true);
        }
    }

    private static void a(Context context, String str, String str2, CloudRequestHandler cloudRequestHandler) {
        com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "handlerLogout", true);
        Intent intent = new Intent(HwAccountConstants.ACTION_LOGOUT_FOR_APP);
        if (!TextUtils.isEmpty(str)) {
            intent.putExtra("userId", str);
        }
        if (!TextUtils.isEmpty(str2)) {
            intent.putExtra(HwAccountConstants.ACCOUNT_KEY, new Account(str2, "com.huawei.hwid"));
        }
        intent.setPackage("com.huawei.hwid");
        com.huawei.hwid.core.d.b.a(context, intent, 0);
    }

    public static void a(Context context, CloudRequestHandler cloudRequestHandler) {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.huawei.hwid.ACTION.BINDSAFEPHONE.SUCCESS");
        if (b.containsKey("BindSafePhoneBroadcastReceiver")) {
            d(context, "BindSafePhoneBroadcastReceiver");
        }
        BroadcastReceiver dVar = new d(context, cloudRequestHandler);
        try {
            context.registerReceiver(dVar, intentFilter);
            a(dVar, "BindSafePhoneBroadcastReceiver");
        } catch (Exception e) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "BroadcastReceiver components are not allowed to register to receive intents", true);
        }
    }

    public static void b(Context context, CloudRequestHandler cloudRequestHandler) {
        if (context == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "context is null", true);
            return;
        }
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.huawei.cloudserive.fingerSuccess");
        intentFilter.addAction("com.huawei.cloudserive.fingerCancel");
        if (b.containsKey("FingerBroadcastReceiver")) {
            d(context, "FingerBroadcastReceiver");
        }
        BroadcastReceiver iVar = new i(context, cloudRequestHandler);
        try {
            context.registerReceiver(iVar, intentFilter);
            a(iVar, "FingerBroadcastReceiver");
        } catch (Exception e) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "BroadcastReceiver components are not allowed to register to receive intents", true);
        }
    }

    public static void a(Context context, Intent intent) {
        HwAccount c = c(context, intent);
        if (c != null && com.huawei.hwid.core.d.b.a(c)) {
            b(context);
            com.huawei.hwid.c.a.a(context).a(context, c);
        }
    }

    public static void a(Context context, String str, boolean z, CloudRequestHandler cloudRequestHandler, Bundle bundle) {
        if (!b(context, str, cloudRequestHandler, bundle)) {
            String str2 = "";
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "checkHwIdPassword", true);
            CloudAccount b = b(context, str);
            if (b == null) {
                str2 = bundle.getString("accountType");
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "get accountType from bundle", true);
                if (TextUtils.isEmpty(str2)) {
                    cloudRequestHandler.onError(new ErrorStatus(12, "the param is invalid"));
                    com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "userId actp is error", true);
                    return;
                }
            }
            str2 = b.getAccountType();
            Intent intent = new Intent();
            b(context, cloudRequestHandler);
            intent.putExtra("userId", str);
            intent.putExtra("accountType", str2);
            intent.putExtra("requestTokenType", context.getPackageName());
            intent.putExtra("startway", 3);
            intent.putExtra("use_finger", z);
            intent.putExtra("receive_package", com.huawei.hwid.core.d.b.c(context));
            intent.putExtras(bundle);
            if (bundle.containsKey("bindOperation")) {
                intent.putExtra(HwAccountConstants.ONLY_BIND_PHONE_FOR_THIRD, 1);
                intent.putExtra("startway", 8);
            }
            if (com.huawei.hwid.core.d.b.b(context, "com.huawei.hwid.FINGER_AUTH")) {
                intent.setAction("com.huawei.hwid.FINGER_AUTH");
                intent.setPackage("com.huawei.hwid");
            } else if (com.huawei.hwid.core.d.b.a(context, HwAccountConstants.ACTION_UID_AUTH, context.getPackageName())) {
                intent.setAction(HwAccountConstants.ACTION_UID_AUTH);
                intent.setPackage(context.getPackageName());
            } else {
                cloudRequestHandler.onError(new ErrorStatus(12, "check pwd activity is null"));
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "check pwd activity is null", true);
                return;
            }
            com.huawei.hwid.core.d.b.a(context, intent, 0);
        }
    }

    private static boolean b(Context context, String str, CloudRequestHandler cloudRequestHandler, Bundle bundle) {
        if (!o.a(context, cloudRequestHandler)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "checkHwIdPassword: context or cloudRequestHandler is null", true);
            return true;
        } else if (cloudRequestHandler == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "cloudRequestHandler is null", true);
            return true;
        } else if (TextUtils.isEmpty(str)) {
            cloudRequestHandler.onError(new ErrorStatus(12, "the param is invalid"));
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "userId is empty", true);
            return true;
        } else if (bundle == null) {
            cloudRequestHandler.onError(new ErrorStatus(12, "the param is invalid"));
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "bundle is null", true);
            return true;
        } else if (!com.huawei.hwid.core.d.b.h(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "can not use hwid checkIsUseHuaweiAccount false", true);
            cloudRequestHandler.onError(new ErrorStatus(33, "hwid is not exit"));
            return true;
        } else if (o.b(context)) {
            return false;
        } else {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "hwid is not exit checkIsInstallHuaweiAccount", true);
            cloudRequestHandler.onError(new ErrorStatus(34, "hwid is not exit"));
            return true;
        }
    }

    private static boolean a(Context context, LoginHandler loginHandler) {
        if (loginHandler == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "loginHandler is null", true);
            return false;
        } else if (context != null) {
            return true;
        } else {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "context is null", true);
            loginHandler.onError(new ErrorStatus(12, "context is null"));
            return false;
        }
    }

    private static boolean a(Context context, IntentResultHandler intentResultHandler) {
        if (intentResultHandler == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "loginHandler is null", true);
            return false;
        } else if (context != null) {
            return true;
        } else {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "context is null", true);
            intentResultHandler.onError(new ErrorStatus(12, "context is null"));
            return false;
        }
    }

    public static void a(Context context, LoginHandler loginHandler, String str) {
        if (context == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "context is null", true);
            return;
        }
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.huawei.hwid.opensdk.smsauth.success");
        intentFilter.addAction("com.huawei.hwid.opensdk.smsauth.quicklogin.SUCCESS");
        intentFilter.addAction("com.huawei.hwid.opensdk.smsauth.quicklogin.fail");
        intentFilter.addAction("com.huawei.hwid.opensdk.switch.other");
        if (b.containsKey("OpenLoginBroadcastReceiver")) {
            d(context, "OpenLoginBroadcastReceiver");
        }
        BroadcastReceiver nVar = new n(context, loginHandler, str);
        try {
            context.registerReceiver(nVar, intentFilter);
            a(nVar, "OpenLoginBroadcastReceiver");
        } catch (Exception e) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "BroadcastReceiver components are not allowed to register to receive intents", true);
        }
    }

    public static void a(Context context, Bundle bundle) {
        if (context == null || bundle == null || b == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "context, bundle or broadcast is null, can't remove broadcast", true);
            return;
        }
        boolean z = bundle.getBoolean("LoginBroadcastReceiver", false);
        boolean z2 = bundle.getBoolean("LogoutBroadcastReceiver", false);
        boolean z3 = bundle.getBoolean("FingerBroadcastReceiver", false);
        boolean z4 = bundle.getBoolean("OpenLoginBroadcastReceiver", false);
        boolean z5 = bundle.getBoolean("BindSafePhoneBroadcastReceiver", false);
        if (z) {
            d(context, "LoginBroadcastReceiver");
        }
        if (z2) {
            d(context, "LogoutBroadcastReceiver");
        }
        if (z3) {
            d(context, "FingerBroadcastReceiver");
        }
        if (z4) {
            d(context, "OpenLoginBroadcastReceiver");
        }
        if (z5) {
            d(context, "BindSafePhoneBroadcastReceiver");
        }
    }

    private static synchronized boolean d(Context context, String str) {
        boolean z;
        synchronized (e.class) {
            z = false;
            ArrayList arrayList = (ArrayList) b.get(str);
            if (!(arrayList == null || arrayList.isEmpty())) {
                Collection arrayList2 = new ArrayList();
                Iterator it = arrayList.iterator();
                while (it.hasNext()) {
                    boolean z2;
                    BroadcastReceiver broadcastReceiver = (BroadcastReceiver) it.next();
                    try {
                        context.unregisterReceiver(broadcastReceiver);
                        arrayList2.add(broadcastReceiver);
                        z2 = true;
                    } catch (Exception e) {
                        com.huawei.hwid.core.d.b.e.c("CloudAccountImpl", "Exception", true);
                        z2 = z;
                    }
                    z = z2;
                }
                if (!arrayList2.isEmpty()) {
                    arrayList.removeAll(arrayList2);
                }
            }
        }
        return z;
    }

    public static synchronized void a(BroadcastReceiver broadcastReceiver, String str) {
        synchronized (e.class) {
            ArrayList arrayList = (ArrayList) b.get(str);
            if (arrayList == null) {
                arrayList = new ArrayList();
            }
            arrayList.add(broadcastReceiver);
            b.put(str, arrayList);
        }
    }

    public static void a(Context context, String str, String str2, String str3, String str4, String str5, String str6, String str7, CloudRequestHandler cloudRequestHandler, Bundle bundle, int i) {
        if (!o.a(context, cloudRequestHandler)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "checkPasswordByUserId: context or cloudRequestHandler is null", true);
        } else if (!a(cloudRequestHandler, str2, str3, str, str5, str6, context)) {
        } else {
            if (com.huawei.hwid.core.d.b.e(str4)) {
                cloudRequestHandler.onError(new ErrorStatus(26, "third account is not allowed to verify password"));
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "third account is not allowed to verify password", true);
            } else if (!com.huawei.hwid.core.d.b.a(context)) {
                cloudRequestHandler.onError(new ErrorStatus(5, context.getString(l.a(context, "CS_no_network_content"))));
                com.huawei.hwid.core.d.b.e.e("CloudAccountImpl", "error: have no network", true);
            } else if (!com.huawei.hwid.core.d.b.h(context)) {
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "checkIsUseHuaweiAccount false can not use hwid", true);
                cloudRequestHandler.onError(new ErrorStatus(33, "hwid is not exit"));
            } else if (o.b(context)) {
                int i2 = 7;
                if (bundle != null) {
                    i2 = bundle.getInt(CloudAccountManager.KEY_REQCLIENTTYPE, 7);
                }
                if (context.getPackageManager().checkPermission("com.huawei.android.permission.ANTITHEFT", str) != 0) {
                    cloudRequestHandler.onError(new ErrorStatus(27, "permission is deny"));
                    com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "permission is deny", true);
                    return;
                }
                com.huawei.hwid.core.b.a.a gVar = new com.huawei.hwid.core.b.a.a.g(context, str2, str, c.b(str3), "0", i2, str5, str6, str7, i);
                gVar.a(context, gVar, null, cloudRequestHandler);
            } else {
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "checkIsInstallHuaweiAccount false hwid is not exit", true);
                cloudRequestHandler.onError(new ErrorStatus(34, "hwid is not exit"));
            }
        }
    }

    private static boolean a(CloudRequestHandler cloudRequestHandler, String str, String str2, String str3, String str4, String str5, Context context) {
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            cloudRequestHandler.onError(new ErrorStatus(12, "the param is invalid"));
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "userId or password is empty", true);
            return false;
        } else if (TextUtils.isEmpty(str3) || !str3.equals(context.getPackageName())) {
            cloudRequestHandler.onError(new ErrorStatus(12, "the param is invalid"));
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "tokenType is empty or not equals", true);
            return false;
        } else if (!TextUtils.isEmpty(str4) && !TextUtils.isEmpty(str5)) {
            return true;
        } else {
            cloudRequestHandler.onError(new ErrorStatus(12, "the param is invalid"));
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "deviceId or deviceType is empty", true);
            return false;
        }
    }

    public static void a(Context context, Bundle bundle, CloudRequestHandler cloudRequestHandler) {
        if (bundle != null) {
            if (!o.a(context, cloudRequestHandler)) {
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "initial: context or cloudRequestHandler is null", true);
            } else if (com.huawei.hwid.core.d.b.a(context)) {
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "configFile is null? " + (com.huawei.hwid.vermanager.b.a(context) == null), true);
                if (!o.b(context)) {
                    com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "hwid is not exit", true);
                    cloudRequestHandler.onError(new ErrorStatus(34, "hwid is not exit"));
                    bundle.putBoolean("updateApk", false);
                } else if (o.a(context, 20300000)) {
                    cloudRequestHandler.onError(new ErrorStatus(35, "hwid low update"));
                    com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "apk version is low", true);
                } else {
                    Bundle bundle2 = new Bundle();
                    bundle2.putString(CloudAccountManager.KEY_VERSION_NAME, o.c(context));
                    cloudRequestHandler.onFinish(bundle2);
                    return;
                }
                d(context);
                com.huawei.hwid.api.common.apkimpl.a.b(context, bundle);
            } else {
                cloudRequestHandler.onError(new ErrorStatus(5, context.getString(l.a(context, "CS_no_network_content"))));
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "error: have no network", true);
            }
        }
    }

    public static void b(Context context, Bundle bundle, CloudRequestHandler cloudRequestHandler) {
        if (bundle == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "updateHwId bunlde is null", true);
        } else if (!o.a(context, cloudRequestHandler)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "updateHwId context or cloudRequestHandler is null", true);
        } else if (!com.huawei.hwid.core.d.b.a(context)) {
            cloudRequestHandler.onError(new ErrorStatus(5, context.getString(l.a(context, "CS_no_network_content"))));
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "error: have no network", true);
        } else if (o.b(context)) {
            com.huawei.hwid.api.common.apkimpl.a.b(context, bundle);
        } else {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "hwid is not exit", true);
            cloudRequestHandler.onError(new ErrorStatus(34, "hwid is not exit"));
            bundle.putBoolean("updateApk", false);
        }
    }

    public static Intent a() {
        Intent intent = new Intent();
        intent.setPackage("com.huawei.hwid");
        intent.setAction(HwAccountConstants.ACTION_HWID_UNIFY_PASSWORD_VERIFY);
        return intent;
    }

    private static void b(HwAccount hwAccount, Context context) {
        Object q = hwAccount.q();
        if (TextUtils.isEmpty(q) || HwAccountConstants.NULL.equalsIgnoreCase(q)) {
            String a = n.a(context, 0);
            if (a == null) {
                a = "";
            }
            hwAccount.p(a);
        }
    }

    public HwAccount b() {
        return this.c;
    }

    private void a(HwAccount hwAccount) {
        this.c = hwAccount;
    }

    public void a(Context context, String str, String str2, int i, CloudRequestHandler cloudRequestHandler) {
        if (!o.a(context, cloudRequestHandler)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "serviceTokenAuth: context or requestHandler is null", true);
        } else if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2) || i < 0) {
            com.huawei.hwid.core.d.b.e.e("CloudAccountImpl", "error: parameter tokenType or st is invalid", true);
            cloudRequestHandler.onError(new ErrorStatus(12, "parameter is invalid"));
        } else if (!com.huawei.hwid.core.d.b.a(context)) {
            com.huawei.hwid.core.d.b.e.e("CloudAccountImpl", " have no network", true);
            cloudRequestHandler.onError(new ErrorStatus(5, context.getString(l.a(context, "CS_no_network_content"))));
        } else if (!com.huawei.hwid.core.d.b.h(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "checkIsUseHuaweiAccount false can not use hwid", true);
            cloudRequestHandler.onError(new ErrorStatus(33, "hwid is not exit"));
        } else if (o.b(context)) {
            d.a(str);
            String str3 = "";
            String str4 = "";
            if (this.c != null) {
                str3 = this.c.i();
                str4 = this.c.k();
            }
            com.huawei.hwid.core.b.a.a fVar = new f(context, str, str2, i, str3, str4);
            fVar.a(context, fVar, null, cloudRequestHandler);
        } else {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "huawei is not exit checkIsInstallHuaweiAccount false", true);
            cloudRequestHandler.onError(new ErrorStatus(34, "hwid is not exit"));
        }
    }

    public String c() {
        return this.c.g();
    }

    public Bundle d() {
        return this.c.t();
    }

    public void e(Context context) {
        if (context == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "cloudAccountimpl context is null", true);
            return;
        }
        if (com.huawei.hwid.core.d.b.h(context) && o.b(context)) {
            com.huawei.hwid.core.d.b.e.e("CloudAccountImpl", "install apk logout", true);
            com.huawei.hwid.api.common.apkimpl.a.a(context, this.c);
        }
        o.a(context, "");
        com.huawei.hwid.c.a.a(context).b(context, com.huawei.hwid.core.d.b.l(context));
        LoginHandler a = o.a();
        com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "gethandle", true);
        if (a != null) {
            a.onLogout(new CloudAccount[0], -1);
        }
    }

    public void a(Context context, String str, CloudRequestHandler cloudRequestHandler) {
        if (!o.a(context, cloudRequestHandler)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "getUserInfo: context or cloudRequestHandler is null", true);
        } else if (!com.huawei.hwid.core.d.b.h(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "can not use hwid", true);
            cloudRequestHandler.onError(new ErrorStatus(33, "hwid is not exit"));
        } else if (o.b(context)) {
            com.huawei.hwid.core.d.b.a(context, this.c.d(), str, cloudRequestHandler);
        } else {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "hwid is not exit", true);
            cloudRequestHandler.onError(new ErrorStatus(34, "hwid is not exit"));
        }
    }

    public boolean a(final Context context, final UserInfo userInfo, final CloudRequestHandler cloudRequestHandler) {
        com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "updateUserInfo enter", true);
        if (!o.a(context, cloudRequestHandler) || userInfo == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "updataUserinfo: context or requestHandler or info is null", true);
            return false;
        } else if (!com.huawei.hwid.core.d.b.h(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "updateUserInfo can not use hwid", true);
            cloudRequestHandler.onError(new ErrorStatus(33, "hwid is not exit"));
            return false;
        } else if (!o.b(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "updateUserInfo hwid is not exit", true);
            cloudRequestHandler.onError(new ErrorStatus(34, "hwid is not exit"));
            return false;
        } else if (o.a(context, 20300000)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "updateUserInfo hwid apk version is low", true);
            cloudRequestHandler.onError(new ErrorStatus(35, "hwid is low version"));
            return false;
        } else {
            Thread anonymousClass3 = new Thread(this) {
                final /* synthetic */ e d;

                public void run() {
                    this.d.b(context, userInfo, cloudRequestHandler);
                }
            };
            anonymousClass3.setName("updateUserInfoThread");
            anonymousClass3.start();
            return true;
        }
    }

    private void a(String str, Context context, CloudRequestHandler cloudRequestHandler) {
        HashMap hashMap = new HashMap();
        String str2 = HwAccountConstants.TYPE_TENCENT;
        hashMap.put("userID", this.c.d());
        hashMap.put(CloudAccountManager.KEY_REQCLIENTTYPE, str2);
        hashMap.put("fileCnt", "1");
        hashMap.put("ver", "27120");
        str2 = a(context, com.huawei.hwid.core.b.a.a.a(), this.c.e());
        if (com.huawei.hwid.core.d.b.a(context)) {
            String a = g.a(context, a(str), str2, hashMap, this.c.b());
            Intent intent = new Intent();
            g.a(a, intent);
            Bundle extras = intent.getExtras();
            if (extras == null) {
                a = "";
            } else {
                a = extras.getString("fileUrlB", "");
            }
            Bundle extras2;
            if (a.isEmpty()) {
                a = "upload headPic faild";
                extras2 = intent.getExtras();
                if (extras2 != null) {
                    a = extras2.getString("errorDesc", a);
                }
                cloudRequestHandler.onError(new ErrorStatus(37, a));
                return;
            }
            extras2 = new Bundle();
            extras2.putBoolean(HwAccountConstants.SERVICETOKENAUTH_IS_SECCUSS, true);
            extras2.putString("url", a);
            cloudRequestHandler.onFinish(extras2);
            return;
        }
        cloudRequestHandler.onError(new ErrorStatus(5, context.getString(l.a(context, "CS_no_network_content"))));
        com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "error: have no network", true);
    }

    public boolean b(Context context, String str, CloudRequestHandler cloudRequestHandler) {
        if (!o.a(context, cloudRequestHandler) || str == null || str.isEmpty()) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "updateHeadPicture: context or requestHandler or info is null", true);
            return false;
        } else if (!com.huawei.hwid.core.d.b.h(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "updateHeadPicture can not use hwid", true);
            cloudRequestHandler.onError(new ErrorStatus(33, "hwid is not exit"));
            return false;
        } else if (!o.b(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "updateHeadPicture hwid is not exit", true);
            cloudRequestHandler.onError(new ErrorStatus(34, "hwid is not exit"));
            return false;
        } else if (o.a(context, 20300000)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "updateHeadPicture hwid apk version is low", true);
            cloudRequestHandler.onError(new ErrorStatus(35, "hwid is low version"));
            return false;
        } else if (a(str) == null) {
            cloudRequestHandler.onError(new ErrorStatus(47, "head pic not exist"));
            return false;
        } else {
            this.g = str;
            this.e = context;
            this.f = cloudRequestHandler;
            a(context, this.c.h(), this.c.g(), this.c.e(), this.h);
            return true;
        }
    }

    private void b(Context context, UserInfo userInfo, CloudRequestHandler cloudRequestHandler) {
        com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "syncUserInfo enter", true);
        if (com.huawei.hwid.core.d.b.a(context)) {
            com.huawei.hwid.core.b.a.a hVar = new h(this.c.d(), null, null, userInfo, null, new Bundle());
            hVar.a(context, this.c.e());
            hVar.a(context, hVar, this.c.b(), cloudRequestHandler);
            return;
        }
        cloudRequestHandler.onError(new ErrorStatus(5, context.getString(l.a(context, "CS_no_network_content"))));
        com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "error: have no network", true);
    }

    private File a(String str) {
        File file = new File(str);
        if (file.exists()) {
            com.huawei.hwid.core.d.b.e.c("CloudAccountImpl", "Photo is existed ", true);
            return file;
        }
        com.huawei.hwid.core.d.b.e.c("CloudAccountImpl", "Photo is not existed ", true);
        return null;
    }

    private String a(Context context, String str, int i) {
        String a = com.huawei.hwid.d.b.a().a(context, i);
        com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "apkAsUrl, AsUrl::=" + a, false);
        String str2 = a + str;
        a = "";
        if (i >= 1 && i <= 999) {
            a = String.valueOf(i);
        }
        Object a2 = m.a(str2, new String[]{"\\{0\\}", a});
        com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "Set mGlobalHostUrl::=" + a2, false);
        if (TextUtils.isEmpty(a2)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "genUpdateHeadUrl is null.", true);
        }
        return a2;
    }

    public AlertDialog a(Activity activity, String str, Bundle bundle, CloudRequestHandler cloudRequestHandler) {
        if (bundle == null) {
            bundle = new Bundle();
        }
        CloudRequestHandler pVar = new p(activity, cloudRequestHandler, this.c);
        bundle.putString("serviceToken", c());
        bundle.putString("deviceId", this.c.i());
        bundle.putString("deviceType", this.c.k());
        bundle.putInt("siteId", this.c.e());
        this.d = com.huawei.hwid.api.common.a.a.a(activity, str, bundle, pVar);
        return this.d;
    }

    public void a(Context context, String str, IntentResultHandler intentResultHandler) {
        if (!a(context, intentResultHandler)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "getAccountsByType: context or handler is null", true);
        } else if (!com.huawei.hwid.core.d.b.h(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "can not use hwid checkIsUseHuaweiAccount false", true);
            intentResultHandler.onError(new ErrorStatus(33, "hwid is not exit"));
        } else if (!o.b(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "false hwid is not exit checkIsInstallHuaweiAccount", true);
            intentResultHandler.onError(new ErrorStatus(34, "hwid is not exit"));
        } else if (e(context, str)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "getIntent hwid version is low", true);
            intentResultHandler.onError(new ErrorStatus(35, "hwid is low version"));
        } else if (this.c == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "getIntent hwid is not login", true);
            intentResultHandler.onError(new ErrorStatus(31, "hwid is not login"));
        } else {
            String d = this.c.d();
            if (TextUtils.isEmpty(d)) {
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "getIntent hwid is not login", true);
                intentResultHandler.onError(new ErrorStatus(31, "hwid is not login"));
                return;
            }
            com.huawei.hwid.api.common.apkimpl.a.a(context, str, d, new Bundle(), intentResultHandler);
        }
    }

    private boolean e(Context context, String str) {
        if (HwAccountConstants.AUTH_APP_LIST_INTENT.equals(str)) {
            return o.a(context, 20504000);
        }
        if (HwAccountConstants.REMOTE_AUTH_INTENT.equals(str) || HwAccountConstants.HOME_COUNTRY_CHANGE_INTENT.equals(str)) {
            return o.a(context, 20502000);
        }
        if (o.a(context, 20503000)) {
            return true;
        }
        return false;
    }

    public void c(Context context, CloudRequestHandler cloudRequestHandler) {
        if (!o.a(context, cloudRequestHandler)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "getRealNameInfo: context or cloudRequestHandler is null", true);
        } else if (!com.huawei.hwid.core.d.b.h(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "getRealNameInfo checkIsUseHuaweiAccount can not use hwid", true);
            cloudRequestHandler.onError(new ErrorStatus(33, "hwid is not exit"));
        } else if (!o.b(context)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "getRealNameInfo hwid is not exit", true);
            cloudRequestHandler.onError(new ErrorStatus(34, "hwid is not exit"));
        } else if (o.a(context, 20503000)) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "getRealNameInfo hwid version is low", true);
            cloudRequestHandler.onError(new ErrorStatus(35, "hwid is low version"));
        } else if (this.c == null) {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "getRealNameInfo hwid is not login", true);
            cloudRequestHandler.onError(new ErrorStatus(31, "hwid is not login"));
        } else {
            String d = this.c.d();
            if (TextUtils.isEmpty(d)) {
                com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "getRealNameInfo hwid is not login", true);
                cloudRequestHandler.onError(new ErrorStatus(31, "hwid is not login"));
                return;
            }
            com.huawei.hwid.api.common.apkimpl.a.a(context, d, cloudRequestHandler);
        }
    }

    public void a(Context context, int i, IntentResultHandler intentResultHandler) {
        String str = "";
        if (i == 0) {
            str = HwAccountConstants.REAL_NAME_INFO_INTENT;
        } else if (1 == i) {
            str = HwAccountConstants.SIMPLE_IDENTY_VERIFY_INTENT;
        } else if (2 == i) {
            str = HwAccountConstants.IDENTY_CAM_VERIFY_INTENT;
        } else if (3 == i) {
            str = HwAccountConstants.BIND_CARD_VERIFY_INTENT;
        } else if (4 == i) {
            str = HwAccountConstants.BIND_SECURITY_MOBILE_VERIFY_INTENT;
        } else if (5 == i) {
            str = HwAccountConstants.IDENTY_CAM_AND_FACE_OCR_VERIFY_INTENT;
        } else {
            com.huawei.hwid.core.d.b.e.b("CloudAccountImpl", "flag is invalid", true);
            return;
        }
        a(context, str, intentResultHandler);
    }
}
